<?php
/**
 * Created by PhpStorm.
 * User: liujun
 * Date: 2018/8/10
 * Time: 下午1:24
 */

namespace PddWechat\Models\User\Data;


use PddWechat\Models\User\Dao\UserPromotionUrlDao;
use PddWechat\Models\User\DataObject\UserDo;

class UserPromotionUrlData
{
    /**
     * User constructor.
     */
    public function __construct()
    {
        $this->userPromotionUrlDao = new UserPromotionUrlDao();
    }

    /**
     * @param string $openId
     * @return \PddWechat\Models\User\DataObject\UserPromotionUrlDo
     */
    public function getUserByOpenId(string $openId){

        /** @var \PddWechat\Models\User\DataObject\UserPromotionUrlDo $doUser */
        $doUser = $this->userPromotionUrlDao->selectByOpenId($openId);
        unset($doUser->password);
        unset($doUser->slat);
        return $doUser;
    }


    /**
     * @param UserDo $userDo
     */
    public function insert(UserDo $userDo){
        $userPromotionUrlDao = new \PddWechat\Models\User\Dao\UserPromotionUrlDao();
        $userPromotionUrlDo = new \PddWechat\Models\User\DataObject\UserPromotionUrlDo();
        $userPromotionUrlDo->openId = $userDo->openId;
        $userPromotionUrlDo->mallUrl = \PddWechat\Library\PddLibrary::addMallUrl($userDo->openId, $userDo->inviteCode);
        $userPromotionUrlDo->redPackUrl = \PddWechat\Library\PddLibrary::addRedPackUrl($userDo->openId, $userDo->inviteCode);
        $userPromotionUrlDao->insert($userPromotionUrlDo);
    }
}